package com.lxd.sunso.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.lxd.sunso.common.utils.PageUtils;
import com.lxd.sunso.common.utils.R;
import com.lxd.sunso.product.vo.MessageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lxd.sunso.product.entity.AlarmregisterEntity;
import com.lxd.sunso.product.service.AlarmregisterService;


/**
 * @author lxd
 * @email sunlightcs@gmail.com
 * @date 2020-12-30 18:06:30
 */
@RestController
@RequestMapping("product/alarmregister")
public class AlarmregisterController {
    @Autowired
    private AlarmregisterService alarmregisterService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("product:alarmregister:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = alarmregisterService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("product:alarmregister:info")
    public R info(@PathVariable("id") Long id) {
        AlarmregisterEntity alarmregister = alarmregisterService.findById(id);

        return R.ok().put("alarmregister", alarmregister);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:alarmregister:save")
    public R save(@RequestBody AlarmregisterEntity alarmregister) {
        alarmregisterService.newsave(alarmregister);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:alarmregister:update")
    public R update(@RequestBody AlarmregisterEntity alarmregister) {
        alarmregister.setIsonwarning("0");
        alarmregisterService.updateById(alarmregister);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:alarmregister:delete")
    public R delete(@RequestBody Long[] ids) {
        alarmregisterService.removeRegister(Arrays.asList(ids));
        return R.ok();
    }

    /**
     * 搜索
     */
    @RequestMapping("/search/{machineName}")
    //@RequiresPermissions("product:alarmregister:delete")
    public R search(@PathVariable String machineName, @RequestParam Map<String, Object> params) {
        PageUtils page = alarmregisterService.search(machineName, params);
        return R.ok().put("list", page);
    }

    /**
     * 不同型号的报警数量统计
     */
    @RequestMapping("/getKindAlarm")
    public R getKindAlarm() {
        List<MessageVo> list = alarmregisterService.getKindAlarm();
        return R.ok().put("data", list);
    }
}
